package cn.tedu.luban.settle.main.consumer;

import cn.tedu.luban.order.protocol.dto.OrderMessageDTO;
import cn.tedu.luban.settle.main.service.SettleService;
import com.tedu.inn.protocol.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RocketMQMessageListener(topic = "order_finish_topic", consumerGroup = "settle_group")
public class SettleOrderConsumer implements RocketMQListener<OrderMessageDTO> {

    @Autowired
    private SettleService settleService;

    @Override
    public void onMessage(OrderMessageDTO orderMessageDTO) {
        try{
            settleService.settle(orderMessageDTO);
        }catch (BusinessException e){
            log.error("对[{}]订单,执行结算失败,异常信息:{}",orderMessageDTO.getOrderNo(),e);
        }

    }

}
